package com.cy.aircompressor.main.ui.Infoover.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import androidx.core.content.ContextCompat;

import com.cy.aircompressor.R;
import com.cy.aircompressor.databinding.StageCylinderLayoutBinding;

public class StageCylinderView extends FrameLayout {
    public StageCylinderView(Context context) {
        this(context, null);
    }

    public StageCylinderView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public StageCylinderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    StageCylinderLayoutBinding mBinding;

    private void initView(Context context) {
        TypedArray typedArray = context.obtainStyledAttributes(new int[]{R.attr.selectableItemBackgroundBorderless});
        Drawable drawable = typedArray.getDrawable(0);
        setBackgroundDrawable(drawable);
        typedArray.recycle();

        LayoutInflater mInflater = LayoutInflater.from(context);
        mBinding = StageCylinderLayoutBinding.inflate(mInflater);
        addView(mBinding.getRoot());
    }


    public void setTitleAndName(String title, String value) {
        mBinding.textTitle.setText(title);
        if (TextUtils.isEmpty(value)) {
            mBinding.textValue.setText("--");
            return;
        }
        mBinding.textValue.setText(value);
    }

    public void setTitle(String title) {
        mBinding.textTitle.setText(title);
    }

    public void setValue(String value) {
        mBinding.textValue.setText(value);
    }

    public void setStatus(Integer status) {
        if (status != 1) {
            mBinding.textTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.grey));
            mBinding.textValue.setTextColor(ContextCompat.getColor(getContext(), R.color.grey));
            mBinding.textUnit.setTextColor(ContextCompat.getColor(getContext(), R.color.grey));
            mBinding.point.getDelegate().setBackgroundColor(ContextCompat.getColor(getContext(), R.color.grey));
        } else {
            mBinding.textTitle.setTextColor(Color.parseColor("#ff4374cd"));
            mBinding.textValue.setTextColor(Color.parseColor("#ff12d71f"));
            mBinding.textUnit.setTextColor(Color.parseColor("#ffffff"));
            mBinding.point.getDelegate().setBackgroundColor(Color.parseColor("#ff4374cd"));
        }
    }

    public void setUnit(String unit) {
        mBinding.textUnit.setText(unit);
    }


}
